package com.tofindaway.service;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.tofindaway.dao.ArticleDao;
import com.tofindaway.dao.UserDao;
import com.tofindaway.entity.Article;
import com.tofindaway.entity.User;
import org.apache.log4j.Logger;

@Repository
public class UserServ {

	private static Logger logger = Logger.getLogger(UserServ.class);
	private UserDao userDao;
	private ArticleDao articleDao;

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public ArticleDao getArticleDao() {
		return articleDao;
	}

	public void setArticleDao(ArticleDao articleDao) {
		this.articleDao = articleDao;
	}

	public void init() {
		logger.debug("userServ init...");
		Assert.notNull(userDao, " userDao cannot be null!");
		Assert.notNull(articleDao, " userDao cannot be null!");
	}

	@Transactional
	public List<User> getUsers() {
		return getUserDao().getList();
	}

	@Transactional
	public List<Article> getArticles() {
		return getArticleDao().getList();
	}

	@Transactional
	public Article findArticleById(Long id) {
		return getArticleDao().findById(id);
	}

	public UserServ() {
		super();
		// TODO Auto-generated constructor stub
	}

}
